←Select platform

Recognize(int,ITemplateForm,int,IEnumerable<Field>) Method

Summary

Performs processing on the IRecognitionForm on the page number and fields provided as parameters.

Syntax
C#
C++/CLI
Python
public void Recognize( 
   int recognitionPageNumber, 
   ITemplateForm templateForm, 
   int templatePageNumber, 
   IEnumerable<Field> fields 
) 
public:  
   void Recognize( 
      Int32 recognitionPageNumber, 
      ITemplateForm^ templateForm, 
      Int32 templatePageNumber, 
      IEnumerable<Field^>^ fields 
   ) 

Parameters

recognitionPageNumber

Integer that represents the page number in the recognition form's Pages collection.

templateForm

The template form object.

templatePageNumber

Integer that represents the page number in the template form Pages collection.

fields

A generic collection of Field to be processed in this IRecognitionForm.

Remarks

The results of recognizing the fields on this filled-in form can be accessed from the Field.Result property.

When the Recognize method is invoked, fields provided as a parameter are aligned and processed in the filled-in form.

Note

The following example is a snippet of a larger example project. To run the larger example project, follow the work flow laid out in the OMREngine example. You can also download the complete Visual Studio 2017 project.

Example
C#
Java
using Leadtools; 
using Leadtools.Barcode; 
using Leadtools.Codecs; 
 
using Leadtools.Forms.Processing.Omr; 
using Leadtools.Forms.Processing.Omr.Fields; 
using Leadtools.Ocr; 
 
public static List<IRecognitionForm> RecognizeMultipleForms(ITemplateForm template, OmrEngine engine) 
{ 
   string[] inputs = Directory.GetFiles(Path.Combine(LEAD_VARS.ImagesDir, @"Forms\OMR Processing\Exam\filled\")); 
   List<IRecognitionForm> recognizedForms = new List<IRecognitionForm>(); 
 
   // each filled form is recognized separately 
   for (int i = 0; i < inputs.Length; i++) 
   { 
      string fileToRecognize = inputs[i]; 
      IRecognitionForm formToRecognize = engine.CreateRecognitionForm(); 
      formToRecognize.Name = string.Format("Exam {0}", i + 1); 
 
      using (RasterImage fileToRecognizeImage = engine.EnginesObject.RasterCodecs.Load(fileToRecognize)) 
      { 
         for (int j = 0; j < fileToRecognizeImage.PageCount; j++) 
         { 
            fileToRecognizeImage.Page = j + 1; 
            formToRecognize.Pages.AddPage(fileToRecognizeImage); 
         } 
 
         formToRecognize.Recognize(template); 
      } 
 
      for (int j = 0; j < formToRecognize.Pages[0].Fields.Count; j++) 
      { 
         OmrField field = formToRecognize.Pages[0].Fields[j] as OmrField; 
 
         if (field != null) 
         { 
            OmrFieldResult omrFieldResult = (OmrFieldResult)field.Result; 
 
            Console.Write(omrFieldResult.Text + "\t"); 
         } 
      } 
      Console.WriteLine(); 
 
      recognizedForms.Add(formToRecognize); 
 
 
   } 
 
   return recognizedForms; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Path; 
import java.util.ArrayList; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
import leadtools.forms.processing.omr.*; 
import leadtools.forms.processing.omr.fields.*; 
import leadtools.ocr.*; 
 
 
public void IRecognizeFormsMultipleFormsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   OmrEngine omrEngine = CreateOmrEngine(); 
 
   // create template for recognition 
   String templateFileName = combine(LEAD_VARS_IMAGES_DIR, "Forms\\OMR Processing\\Exam\\exam.tif"); 
   RasterImage templateImage = omrEngine.getEnginesObject().getRasterCodecs().load(templateFileName, 0, 
         CodecsLoadByteOrder.BGR, 1, 1); 
   ITemplateForm template = CreateNewTemplate(templateImage, omrEngine); 
   AddZonesToTemplate(template); 
 
   // gather filled forms for recognition 
   String absPath = combine(LEAD_VARS_IMAGES_DIR, "Forms\\OMR Processing\\Exam\\filled"); 
   File dir = new File(absPath); 
   dir.mkdirs(); 
   String[] inputs = dir.list(); 
   List<IRecognitionForm> recognizedForms = new ArrayList<IRecognitionForm>(); 
 
   for (int i = 0; i < inputs.length; i++) { 
      assertTrue(inputs[i] != null); 
      System.out.println(Path.of(inputs[i]).toAbsolutePath().toString()); 
   } 
 
   // each filled form is recognized separately 
   for (int i = 0; i < inputs.length; i++) { 
      String fileToRecognize = inputs[i]; 
      IRecognitionForm formToRecognize = omrEngine.createRecognitionForm(); 
      formToRecognize.setName(String.format("Exam %s", i + 1)); 
      RasterImage fileToRecognizeImage = omrEngine.getEnginesObject().getRasterCodecs() 
            .load(combine(absPath, fileToRecognize)); 
 
      for (int j = 0; j < fileToRecognizeImage.getPageCount(); j++) { 
         fileToRecognizeImage.setPage(j + 1); 
         formToRecognize.getPages().addPage(fileToRecognizeImage); 
      } 
      formToRecognize.recognize(template); 
 
      for (int j = 0; j < formToRecognize.getPages().getPage(1).getFields().size(); j++) { 
         OmrField field = (OmrField) formToRecognize.getPages().getPage(1).getFields().get(j); 
 
         if (field != null) { 
            OmrFieldResult omrFieldResult = (OmrFieldResult) field.getResult(); 
            System.out.print(omrFieldResult.getText() + "\t"); 
         } 
      } 
      System.out.println(); 
      recognizedForms.add(formToRecognize); 
   } 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Forms.Processing.Omr Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.